package com.yycx.module.bus.provider.controller;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusSfinanceDetails;
import com.yycx.module.bus.provider.service.BusSfinanceDetailsService;
import com.yycx.module.bus.provider.service.BusSfinanceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 厂家对账明细控制器
 *
 * @author flyme
 * @date 2021-02-19
 */
@RestController
@RequestMapping("/bus/bsd/")
public class BusSfinanceDetailsController extends BaseController<BusSfinanceDetailsService, BusSfinanceDetails> {

    @Autowired
    private BusSfinanceService busSfinanceService;

    @ApiOperation(value = "厂家对账明细-分页列表", notes = "厂家对账明细分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "厂家对账明细-列表", notes = "厂家对账明细列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Long sfinanceId) {
        Map<String, Object> map = (Map) redisUtils.get("SDZ:" + sfinanceId);
        if (FlymeUtils.isEmpty(map)) {
            map = busSfinanceService.initData(sfinanceId);
        }
        EntityMap result = new EntityMap();
        Object orderDetailList = map.get("orderDetailList");
        Object lastReturnList = map.get("lastReturnList");
        Object lastFanList = map.get("lastFanList");
        Object lastTuiDianList = map.get("lastTuiDianList");
        Object lastDianList = map.get("lastDianList");
        Object lastDetailList = map.get("lastDetails");
        result.put("orderDetailList", orderDetailList);
        result.put("lastReturnList", lastReturnList);
        result.put("lastFanList", lastFanList);
        result.put("lastDianList", lastDianList);
        result.put("lastTuiDianList", lastTuiDianList);
        result.put("lastDetailList", lastDetailList);
        return ResultBody.ok(result);
    }

    @ApiOperation(value = "厂家对账明细-添加", notes = "添加厂家对账明细")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "厂家对账明细-更新", notes = "更新厂家对账明细")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "厂家对账明细-删除", notes = "删除厂家对账明细")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "厂家对账明细-详情", notes = "厂家对账明细详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

}
